!include "MUI.nsh"

; The name of the installer
Name "Nagaina"

SetCompressor lzma

; The file to write
OutFile "../../../bin/Nagaina-Setup.exe"

XPStyle on

; The default installation directory
InstallDir $PROGRAMFILES\Nagaina

; Registry key to check for directory (so if you install again, it will 
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\Nagaina" "Install_Dir"

;--------------------------------

; Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "../../../LICENSE"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
  
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;--------------------------------

!insertmacro MUI_LANGUAGE "English"

; The stuff to install
Section "Nagaina" MainSection

  ; Read Only section. Can't be disabled by user.
  SectionIn RO
  
  ; Set output path to the installation directory.
  SetOutPath $INSTDIR
  
  ; Put file there
  File "..\..\..\bin\nagaina.exe"
  File "..\..\..\bin\dll\mingwm10.dll"
  File "..\..\..\images\nagaina.ico"
  File "..\..\..\CHANGELOG"
  File "..\..\..\LICENSE"
  
  ; Write the installation path into the registry
  WriteRegStr HKLM SOFTWARE\Nagaina "Install_Dir" "$INSTDIR"
  
  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Nagaina" "DisplayName" "Nagaina"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Nagaina" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Nagaina" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Nagaina" "NoRepair" 1
  WriteUninstaller "uninstall.exe"
  
SectionEnd

Section "Qt runtime" QtRuntimeSection
  SetOutPath $INSTDIR
  
  ; File "..\..\..\bin\dll\Qt3Support4.dll"
  File "..\..\..\bin\dll\QtCore4.dll"
  File "..\..\..\bin\dll\QtGui4.dll"
  File "..\..\..\bin\dll\QtXml4.dll"
SectionEnd

; Optional section (can be disabled by the user)
Section "Start menu shortcuts" ShortcutSection
  ; Needed to set "Start in" field correctly on short cuts
  SetOutPath $INSTDIR

  CreateDirectory "$SMPROGRAMS\Nagaina"
  CreateShortCut "$SMPROGRAMS\Nagaina\Uninstall Nagaina.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
  CreateShortCut "$SMPROGRAMS\Nagaina\Nagaina.lnk" "$INSTDIR\nagaina.exe" "" "$INSTDIR\nagaina.exe" 0
  
SectionEnd

;--------------------------------

; Uninstaller

Section "Uninstall"
  
  ; Remove registry keys
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Nagaina"
  DeleteRegKey HKLM SOFTWARE\Nagaina

  ; Remove files and uninstaller
  Delete "$INSTDIR\nagaina.exe"
  Delete "$INSTDIR\mingwm10.dll"
  ; Delete "$INSTDIR\Qt3Support4.dll"
  Delete "$INSTDIR\QtCore4.dll"
  Delete "$INSTDIR\QtGui4.dll"
  Delete "$INSTDIR\QtXml4.dll"
  Delete "$INSTDIR\nagaina.ico"
  Delete "$APPDATA\nagaina\nagaina.ini"
  Delete "$APPDATA\nagaina\styles.xml"
  Delete "$APPDATA\nagaina\templates.xml"
  Delete "$APPDATA\nagaina\images\*.*"
  Delete "$INSTDIR\CHANGELOG"
  Delete "$INSTDIR\LICENSE"
  Delete "$INSTDIR\uninstall.exe"

  ; Remove shortcuts, if any
  Delete "$SMPROGRAMS\Nagaina\*.*"

  ; Remove directories used  
  RMDir "$APPDATA\nagaina\images"
  RMDir "$APPDATA\nagaina"
  RMDir "$SMPROGRAMS\Nagaina"
  RMDir "$INSTDIR"

SectionEnd

LangString DESC_MainSection ${LANG_ENGLISH} "Nagaina's main files."
LangString DESC_QtRuntimeSection ${LANG_ENGLISH} "Qt Runtime. Uncheck if you have Qt already installed. Leave check if unsure."
LangString DESC_ShortcutSection ${LANG_ENGLISH} "Add shortcuts tu start menu."

!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${MainSection} $(DESC_MainSection)
  !insertmacro MUI_DESCRIPTION_TEXT ${QtRuntimeSection} $(DESC_QtRuntimeSection)
  !insertmacro MUI_DESCRIPTION_TEXT ${ShortcutSection} $(DESC_ShortcutSection)
!insertmacro MUI_FUNCTION_DESCRIPTION_END

